package com.example.untils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/9/8 8:51 上午
 */
@Component
public class JJWTUntil {
    /**
     * 设置过期时间,一周
     */
    private static final long EXPIRE = 7 * 24 * 60 * 60 * 1000;
    // private static final long EXPIRE = 30 * 1000;

    /**
     * 设置秘钥
     * 盐的作用
     */
    private static final String SECRET = "niuma";//盐值

    /**
     * 令牌前缀
     */
    private static final String TOKEN_PREFIX = "niuma";

    /**
     * 令牌主题 - 瞎写的
     */
    private static final String SUBJECT = "niuma";


    /**
     * 校验token的方法
     * @param token
     * @return
     */
    public static Claims checkJWT(String token){
        try{
            final Claims claims = Jwts.parser().setSigningKey(SECRET)
                    .parseClaimsJws(token.replace(TOKEN_PREFIX,"")).getBody();

            return claims;

        }catch (Exception e){
            return null;
        }
    }
}

